package com.kaifamiao.month03.day0314;

import java.util.Arrays;

public class Garde {

    public static void main(String[] args) {
        String[] course = {"java", "c++", "python"};
        int[][] scores = {{99, 95, 100}, {80, 90, 86}, {60, 66, 90}, {70, 99, 88}};
        String[] names = {"张三", "李四", "王五", "孙六"};
//        int[] sums = new int[names.length];
        // 获取每个人的总成绩
        int len = scores[0].length;
        for(int i = 0; i < scores.length; i ++){
            scores[i] = Arrays.copyOf(scores[i],len + 1);
            int sum = 0;
            for(int j = 0; j < scores[i].length; j ++){
                sum += scores[i][j];
            }
            scores[i][len] = sum;
        }

        for(int i = 0; i < names.length - 1; i ++){
            for(int j = 0; j < names.length - 1 - i; j ++){
                if(scores[j][len] < scores[j + 1][len]){
                    int[] temp = scores[j];
                    scores[j] = scores[j + 1];
                    scores[j + 1] = temp;

                    String name = names[j];
                    names[j] = names[j + 1];
                    names[j + 1] = name;
                }
            }
        }
        System.out.print("排名" + "\t");
        System.out.print("姓名" + "\t");
        System.out.print("总分" + "\t");
        for(int j = 0; j < course.length; j ++){
            System.out.print(course[j] + "\t");
        }
        System.out.println();
        for(int i = 0; i < names.length; i ++){
            System.out.print((i + 1) + "\t");
            System.out.print(names[i] + "\t");
            System.out.print(scores[i][len] + "\t");
            for(int j = 0; j < len; j ++){
                System.out.print(scores[i][j] + "\t");
            }
            System.out.println();
        }




//        // 给学生对象数组的属性分别赋值
//        Student[] students = new Student[names.length];
//        for(int i = 0; i < students.length; i ++){
//            Student stu = new Student();
//            stu.name = names[i];
//            stu.sum = sums[i];
//            stu.javaScore = scores[i][0];
//            stu.cScore = scores[i][1];
//            stu.pythonScore = scores[i][2];
//        }

//        for(int i = 0; i < students.length - 1; i ++){
//            for(int j = 0; j < students.length - 1 - i; j ++){
//                if(students[j].sum < students[j + 1].sum){
//                    Student temp = students[j];
//                    students[j] = students[j + 1];
//                    students[j + 1] = temp;
//                }
//            }
//        }
//        System.out.println("姓名  总分   java   c++   python");
//        for (Student student : students) {
//            student.show();
//        }


    }
}
